package com.richard.springcloud.controller;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import com.richard.cloud.entity.Payment;
import com.richard.springcloud.base.ComnResult;
import com.richard.springcloud.feign.PaymentServiceFeign;

@RestController
public class OrderController {
	private static final String PAYMENT_URL = "http://localhost:8001/payment";
	private static final String HTTP_PREFIX = "http://";
	@Value("${provider.name.payment}")
	private String PAYMENT_SVS;
	
	@Resource
	private PaymentServiceFeign paymentFeignService;
	
	@Resource
	private RestTemplate restTemplate;
	
	@GetMapping("/order/payment/{id}")
	public ComnResult<Payment> get(@PathVariable Long id) {
		System.out.println(PAYMENT_SVS);
//		ComnResult resp = restTemplate.getForObject(PAYMENT_URL + "/" + id, ComnResult.class);
//		ComnResult resp = restTemplate.getForObject(HTTP_PREFIX + PAYMENT_SVS + "/payment/" + id, ComnResult.class);
//		ComnResult<Payment> resp = paymentFeignService.getPaymentInfo(id);
		Payment paymentInfo = paymentFeignService.getPaymentInfo(id);
		return new ComnResult(paymentInfo);
	}
}
